/*
 * File: Look2D_U16_U8_U16.c
 *
 * Code generated for Simulink model 'SOCE'.
 *
 * Model version                  : 3.241
 * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
 * C/C++ source code generated on : Tue May 10 15:48:28 2022
 */

#include "rtwtypes.h"
#include "BINARYSEARCH_U8.h"
#include "BINARYSEARCH_U16.h"
#include "INTERPOLATE_U16_U16.h"
#include "INTERPOLATE_U16_U8.h"
#include "Look2D_U16_U8_U16.h"

/* Lookup 2D Lookup Utility Look2D_U16_U8_U16 */
void Look2D_U16_U8_U16(uint16_T *pY, const uint16_T *pYData, uint8_T u0, const
                       uint8_T *pU0Data, uint32_T iHiU0, uint16_T u1, const
                       uint16_T *pU1Data, uint32_T iHiU1)
{
    uint32_T iLeftU0, iRghtU0, iLeftU1, iRghtU1;
    BINARYSEARCH_U8( &(iLeftU0), &(iRghtU0), u0, pU0Data, iHiU0);
    BINARYSEARCH_U16( &(iLeftU1), &(iRghtU1), u1, pU1Data, iHiU1);

    {
        uint8_T u0Left = pU0Data[iLeftU0];
        uint8_T u0Rght = pU0Data[iRghtU0];
        uint16_T u1Left = pU1Data[iLeftU1];
        uint16_T u1Rght = pU1Data[iRghtU1];
        uint16_T yTemp;
        uint16_T yLeftLeft;
        uint16_T yLeftRght;
        uint16_T yRghtLeft;
        uint16_T yRghtRght;
        iHiU0++;
        iLeftU1 *= iHiU0;
        iRghtU1 *= iHiU0;
        yRghtLeft = pYData[(iRghtU0+iLeftU1)];
        yRghtRght = pYData[(iRghtU0+iRghtU1)];
        yLeftLeft = pYData[(iLeftU0+iLeftU1)];
        yLeftRght = pYData[(iLeftU0+iRghtU1)];

        /* Interpolate along U1 variable
         *    with the u0 variable locked on the left u0
         */
        INTERPOLATE_U16_U16( pY, yLeftLeft, yLeftRght, u1, u1Left, u1Rght);

        /* Interpolate along U1 variable
         *    with the u0 variable locked on the right u0
         */
        INTERPOLATE_U16_U16( (&(yTemp)), yRghtLeft, yRghtRght, u1, u1Left,
                            u1Rght);

        /*
         * Interpolate along u0 variable
         *    with the u1 variable locked on its interpolated value
         */
        INTERPOLATE_U16_U8( pY, (*pY), yTemp, u0, u0Left, u0Rght);
    }
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
